//
//  XMAlterView.m
//  XMKit
//
//  Created by Ce Liu on 2018/6/1.
//  Copyright © 2018年 ChenXiaoMing. All rights reserved.
//

#import "XMAlterView.h"

static const CGFloat kContentHeight = 150.0f;

@interface XMAlterView ()
// containerView
@property (nonatomic,strong) UIView *containerView;
// items
@property (nonatomic, strong) NSArray *itemArray;

@property (nonatomic, strong) NSString *cancelItem;

@end

@implementation XMAlterView

- (instancetype)initWithItems:(NSArray *)items cancelItem:(NSString *)cancelItem {
    if (self = [super init]) {
        self.frame = [UIScreen mainScreen].bounds;
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.85];
        _alterHeight = 150.f;
        self.containerView.frame = CGRectMake(0, kSCREENHEIGHT, kSCREENWIDTH, _alterHeight);
        [self addSubview:self.containerView];
        
    }
    return self;
}

- (UIView *)containerView {
    if (!_containerView) {
        _containerView = [[UIView alloc] init];
        _containerView.backgroundColor = [UIColor whiteColor];
    }
    return _containerView;
}

- (void)show {
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    [keyWindow addSubview:self];
    [UIView animateWithDuration:0.35 animations:^{
        self.containerView.frame = CGRectMake(0, kSCREENHEIGHT - _alterHeight, kSCREENWIDTH, _alterHeight);
    }];
}


-(void)dismissAlterView {
    [UIView animateWithDuration:0.35 animations:^{
        _containerView.frame = CGRectMake(0, kSCREENHEIGHT, kSCREENHEIGHT, _alterHeight);
    } completion:^(BOOL finished) {
        [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [self removeFromSuperview];
    }];
}

@end
